package com.new2i.action;
 
import java.util.HashMap; 

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.new2i.aop.LoginInterceptor;
import com.new2i.model.DoctorEntity;
import com.new2i.model.DoctorUserEntity; 
import com.new2i.service.able.DoctorUserService; 
/**
 * 医生的用户视图控制器－视图
 * 
 * @since 2015/09/01
 * @author 2i
 *
 */
@Controller
@RequestMapping("page/users")
public class DoctorUserPageAction extends BaseAction {
	
	@Autowired
	private transient DoctorUserService mDoctorUserService;
	
	private static Logger logger = Logger.getLogger(DoctorUserPageAction.class);
	
	/**
	 * 用户列表以及分组列表
	 * 
	 * @author 2i
	 * @since 2015/09/01
	 * @param request
	 * @param response 
	 * @return
	 */
	@LoginInterceptor
	@RequestMapping("/list")
	public ModelAndView contactListPage(HttpServletRequest request, HttpServletResponse response, DoctorEntity doctor,
			DoctorUserEntity doctorUser) {
		ModelAndView mav = new ModelAndView();  
		doctorUser.setDoctor_id(doctor.getDoctor_id()); 
		HashMap<String,Object> map = mDoctorUserService.getUserListAndCount(doctorUser);  
		mav.setViewName("/views/user_list.jsp");
		mav.addAllObjects(map); 
		return mav;
	}
	 
	/**
	 * 用户信息以及病历列表
	 * 
	 * @author 2i
	 * @since 2015/09/01
	 * @param request
	 * @param response
	 * @param doctor
	 * @return
	 */
	@LoginInterceptor
	@RequestMapping(value = "/{user_id}", method = RequestMethod.GET)
	public ModelAndView userInfoAndEmrListPage(@PathVariable int user_id,HttpServletRequest request, HttpServletResponse response, DoctorEntity doctor){
		DoctorUserEntity doctorUser = new DoctorUserEntity();
		logger.debug("user_id==>" + user_id);
		doctorUser.setDoctor_id(doctor.getDoctor_id()); 
		doctorUser.setUser_id(user_id);
		ModelAndView mav = new ModelAndView();   
		HashMap<String,Object> map = mDoctorUserService.getUserInfoAndEmrList(doctorUser);  
		mav.setViewName("/views/user_info.jsp");
		mav.addAllObjects(map); 
		logger.debug("user_info ==>" + map); 
		return mav;
	} 
}
